package cn.tedu.pojo;

import org.springframework.format.annotation.DateTimeFormat;

import java.util.Arrays;
import java.util.Date;

//封装网页中发来的数据
public class Student {
    //注意：一般在封装类的时候一般不用基本类型，用引用类型，因为基本类型的数据在提交时如果有没有填完数据就提交会出现空指针异常。
    //所报的空指针异常：java.lang.NullPointerException: null
    private  String user;//封装网页中输入的用户
    private  int age;//封装网页中输入的年龄
    private int sex;//封装网页中输入的性别
    private String[] hobby;//封装网页中选择的多个爱好
    private int edu;//封装网页中选择的学历
    //格式化日期的:浏览器上选择的日期是String类型，要转成Date类型就要使用注解，否则网页里要报404的错误
    @DateTimeFormat(pattern = "yyy-MM-dd")
    private Date intime;//封装网页中填的日期
    //set/get ...toString

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String[] getHobby() {
        return hobby;
    }

    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }

    public int getEdu() {
        return edu;
    }

    public void setEdu(int edu) {
        this.edu = edu;
    }

    public Date getIntime() {
        return intime;
    }

    public void setIntime(Date intime) {
        this.intime = intime;
    }

    @Override
    public String toString() {
        return "Student{" +
                "user='" + user + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", hobby=" + Arrays.toString(hobby) +
                ", edu=" + edu +
                ", intime=" + intime.toLocaleString() +/*toLocaleString()打印成2021-5-20的格式*/
                '}';
    }
}
